class Solution {
public:
    void recursion(int left, int right, string temp, vector<string>& res, int n) {
        if(left == n && right == n) {
            res.push_back(temp);
            return;
        }

        if(left < n)
            recursion(left + 1, right, temp + "(", res, n);
        if(right < n && right < left)
            recursion(left, right + 1, temp + ")", res, n);
    }

    vector<string> generateParenthesis(int n) {
        vector<string> res;
        string temp;
        recursion(0, 0, temp, res, n);
        return res;        
    }

};